{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 知识阶段性总结（知识考查）\n",
    "\n",
    "* 本周主要内容：高德API\n",
    "* 20春_API_人工智能与机器学习_week05\n",
    "*  电子讲义设计者：许智超，廖汉腾\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "## 上周回顾：\n",
    "1. 地图API简介（Web服务）\n",
    "2. 如何选择合适的API（开发支持）\n",
    "3. 权衡经济成本和产品设计成本（调用量和并发量思考，经济成本考量）\n",
    "4. 设计地图url需求\n",
    "5. 测试API功能\n",
    "    1. 地理编码/逆地理编码\n",
    "    2. 路径规划\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "----\n",
    "\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "# 细读地图API（高德）\n",
    "\n",
    "\n",
    "\n",
    "## 本周内容介绍\n",
    "\n",
    "* 关键：如何详细阅读和使用API参数\n",
    "    1. 回顾地理编码、逆地理编码、步行路径规划\n",
    "    2. 路径规划2\n",
    "    3. 搜索POI\n",
    "    4. IP定位\n",
    "    5. 批量请求借口\n",
    "    6. 静态地图\n",
    "    7. 坐标转换 \n",
    "    8. 交通态势\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "/* 本电子讲义使用之CSS */\n",
       "div.code_cell {\n",
       "    background-color: #e5f1fe;\n",
       "}\n",
       "div.cell.selected {\n",
       "    background-color: #effee2;\n",
       "    font-size: 2rem;\n",
       "    line-height: 2.4rem;\n",
       "}\n",
       "div.cell.selected .rendered_html table {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html pre code {\n",
       "    background-color: #C4E4ff;   \n",
       "    padding: 2px 25px;\n",
       "}\n",
       ".rendered_html pre {\n",
       "    background-color: #99c9ff;\n",
       "}\n",
       "div.code_cell .CodeMirror {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html img, .rendered_html svg {\n",
       "    max-width: 100%;\n",
       "    height: auto;\n",
       "    float: center;\n",
       "}\n",
       "/* Gradient transparent - color - transparent */\n",
       "hr {\n",
       "    border: 0;\n",
       "    border-bottom: 1px dashed #ccc;\n",
       "}\n",
       ".emoticon{\n",
       "    font-size: 5rem;\n",
       "    line-height: 4.4rem;\n",
       "    text-align: center;\n",
       "    vertical-align: middle;\n",
       "}\n",
       "\n",
       "</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "/* 本电子讲义使用之CSS */\n",
    "div.code_cell {\n",
    "    background-color: #e5f1fe;\n",
    "}\n",
    "div.cell.selected {\n",
    "    background-color: #effee2;\n",
    "    font-size: 2rem;\n",
    "    line-height: 2.4rem;\n",
    "}\n",
    "div.cell.selected .rendered_html table {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html pre code {\n",
    "    background-color: #C4E4ff;   \n",
    "    padding: 2px 25px;\n",
    "}\n",
    ".rendered_html pre {\n",
    "    background-color: #99c9ff;\n",
    "}\n",
    "div.code_cell .CodeMirror {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html img, .rendered_html svg {\n",
    "    max-width: 100%;\n",
    "    height: auto;\n",
    "    float: center;\n",
    "}\n",
    "/* Gradient transparent - color - transparent */\n",
    "hr {\n",
    "    border: 0;\n",
    "    border-bottom: 1px dashed #ccc;\n",
    "}\n",
    ".emoticon{\n",
    "    font-size: 5rem;\n",
    "    line-height: 4.4rem;\n",
    "    text-align: center;\n",
    "    vertical-align: middle;\n",
    "}\n",
    "\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 回顾地理编码、逆地理编码、步行路径规划（代码A）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "key_xu =\"1a8b4a8f8eacf6e72af8287289e0e270\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A-1 获取地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'OK', 'infocode': '10000', 'count': '1', 'geocodes': [{'formatted_address': '广东省广州市从化区中山大学南方学院', 'country': '中国', 'province': '广东省', 'citycode': '020', 'city': '广州市', 'district': '从化区', 'township': [], 'neighborhood': {'name': [], 'type': []}, 'building': {'name': [], 'type': []}, 'adcode': '440117', 'street': [], 'number': [], 'location': '113.679287,23.632575', 'level': '兴趣点'}]}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>formatted_address</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>citycode</th>\n",
       "      <th>city</th>\n",
       "      <th>district</th>\n",
       "      <th>township</th>\n",
       "      <th>adcode</th>\n",
       "      <th>street</th>\n",
       "      <th>number</th>\n",
       "      <th>location</th>\n",
       "      <th>level</th>\n",
       "      <th>neighborhood.name</th>\n",
       "      <th>neighborhood.type</th>\n",
       "      <th>building.name</th>\n",
       "      <th>building.type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省广州市从化区中山大学南方学院</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东省</td>\n",
       "      <td>020</td>\n",
       "      <td>广州市</td>\n",
       "      <td>从化区</td>\n",
       "      <td>[]</td>\n",
       "      <td>440117</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.679287,23.632575</td>\n",
       "      <td>兴趣点</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   formatted_address country province citycode city district township  adcode  \\\n",
       "0  广东省广州市从化区中山大学南方学院      中国      广东省      020  广州市      从化区       []  440117   \n",
       "\n",
       "  street number              location level neighborhood.name  \\\n",
       "0     []     []  113.679287,23.632575   兴趣点                []   \n",
       "\n",
       "  neighborhood.type building.name building.type  \n",
       "0                []            []            []  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中大南方地理编码: 113.679287,23.632575\n"
     ]
    }
   ],
   "source": [
    "# A-1 地理编码\n",
    "def geocode(address,city=None,batch=None,sig=None)->dict:\n",
    "    \"\"\"获取地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params={\n",
    "        'key': key_xu,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "中大南方 = geocode(address='广东省广州市从化区中山大学南方学院')\n",
    "print(中大南方)\n",
    "df_中大南方地理编码 = pd.json_normalize(中大南方['geocodes'])\n",
    "display(df_中大南方地理编码)\n",
    "中大南方地理编码 = 中大南方['geocodes'][0]['location']\n",
    "print(\"中大南方地理编码:\",中大南方地理编码)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A-2 逆地理编码（基础/全）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'regeocode': {'addressComponent': {'city': '广州市', 'province': '广东省', 'adcode': '440117', 'district': '从化区', 'towncode': '440117103000', 'streetNumber': {'number': '7号', 'location': '113.6786,23.6333289', 'direction': '西北', 'distance': '109.203', 'street': '博学路'}, 'country': '中国', 'township': '温泉镇', 'businessAreas': [[]], 'building': {'name': [], 'type': []}, 'neighborhood': {'name': [], 'type': []}, 'citycode': '020'}, 'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院'}, 'info': 'OK', 'infocode': '10000'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>info</th>\n",
       "      <td>OK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>infocode</th>\n",
       "      <td>10000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.city</th>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.province</th>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.adcode</th>\n",
       "      <td>440117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.district</th>\n",
       "      <td>从化区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.towncode</th>\n",
       "      <td>440117103000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.number</th>\n",
       "      <td>7号</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.location</th>\n",
       "      <td>113.6786,23.6333289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.direction</th>\n",
       "      <td>西北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.distance</th>\n",
       "      <td>109.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.street</th>\n",
       "      <td>博学路</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.country</th>\n",
       "      <td>中国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.township</th>\n",
       "      <td>温泉镇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.businessAreas</th>\n",
       "      <td>[[]]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.building.name</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.building.type</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.neighborhood.name</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.neighborhood.type</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.citycode</th>\n",
       "      <td>020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.formatted_address</th>\n",
       "      <td>广东省广州市从化区温泉镇中山大学南方学院</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                      0\n",
       "status                                                                1\n",
       "info                                                                 OK\n",
       "infocode                                                          10000\n",
       "regeocode.addressComponent.city                                     广州市\n",
       "regeocode.addressComponent.province                                 广东省\n",
       "regeocode.addressComponent.adcode                                440117\n",
       "regeocode.addressComponent.district                                 从化区\n",
       "regeocode.addressComponent.towncode                        440117103000\n",
       "regeocode.addressComponent.streetNumber.number                       7号\n",
       "regeocode.addressComponent.streetNumber.location    113.6786,23.6333289\n",
       "regeocode.addressComponent.streetNumber.direction                    西北\n",
       "regeocode.addressComponent.streetNumber.distance                109.203\n",
       "regeocode.addressComponent.streetNumber.street                      博学路\n",
       "regeocode.addressComponent.country                                   中国\n",
       "regeocode.addressComponent.township                                 温泉镇\n",
       "regeocode.addressComponent.businessAreas                           [[]]\n",
       "regeocode.addressComponent.building.name                             []\n",
       "regeocode.addressComponent.building.type                             []\n",
       "regeocode.addressComponent.neighborhood.name                         []\n",
       "regeocode.addressComponent.neighborhood.type                         []\n",
       "regeocode.addressComponent.citycode                                 020\n",
       "regeocode.formatted_address                        广东省广州市从化区温泉镇中山大学南方学院"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# A-2 基础逆地理编码分析\n",
    "def regeocode(location,poitype=None,radius=None,extensions=\"base\",batch=False,roadlevel=None,sig=None,homeorcorp=None)->dict:\n",
    "    \"\"\"获取逆地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'\n",
    "    params={\n",
    "        'key': key_xu,\n",
    "        'location':location,\n",
    "        'poitype':poitype,\n",
    "        'radius':radius,\n",
    "        'extensions':extensions,\n",
    "        'batch':batch,\n",
    "        'roadlevel':roadlevel,\n",
    "        'homeorcorp':homeorcorp,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "中大南方逆地理编码_base = regeocode(中大南方地理编码)\n",
    "print(中大南方逆地理编码)\n",
    "df_中大南方逆地理编码 = pd.json_normalize(中大南方逆地理编码).T\n",
    "display(df_中大南方逆地理编码)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'regeocode': {'roads': [{'id': '020F49F0050461203', 'location': '113.68,23.634', 'direction': '南', 'name': '博学路', 'distance': '156.951'}, {'id': '020F49F0050462451', 'location': '113.677,23.6347', 'direction': '东南', 'name': '中山路', 'distance': '343.951'}, {'id': '020F49F006047765', 'location': '113.682,23.6394', 'direction': '南', 'name': 'S29从莞深高速', 'distance': '807.947'}], 'roadinters': [{'second_name': '中山路', 'first_id': '020F49F0050461203', 'second_id': '020F49F0050462451', 'location': '113.6767944,23.63466139', 'distance': '343.951', 'first_name': '博学路', 'direction': '东南'}], 'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院', 'addressComponent': {'city': '广州市', 'province': '广东省', 'adcode': '440117', 'district': '从化区', 'towncode': '440117103000', 'streetNumber': {'number': '7号', 'location': '113.6786,23.6333289', 'direction': '西北', 'distance': '109.203', 'street': '博学路'}, 'country': '中国', 'township': '温泉镇', 'businessAreas': [[]], 'building': {'name': [], 'type': []}, 'neighborhood': {'name': [], 'type': []}, 'citycode': '020'}, 'aois': [{'area': '536585.849985', 'type': '141201', 'id': 'B00140MR9A', 'location': '113.679262,23.632583', 'adcode': '440117', 'name': '中山大学南方学院', 'distance': '0'}], 'pois': [{'id': 'B00140MR9A', 'direction': '西', 'businessarea': [], 'address': '温泉大道882号', 'poiweight': '0.450402', 'name': '中山大学南方学院', 'location': '113.679262,23.632583', 'distance': '2.69979', 'tel': '020-61787326;020-61787333', 'type': '科教文化服务;学校;高等院校'}, {'id': 'B0FFF2VMJ4', 'direction': '东南', 'businessarea': [], 'address': '温泉大道886号中山大学南方学院内', 'poiweight': '0.148531', 'name': '中山大学南方学院-综合楼', 'location': '113.680117,23.631544', 'distance': '142.466', 'tel': [], 'type': '科教文化服务;学校;学校'}, {'id': 'B0FFFTC9PH', 'direction': '东北', 'businessarea': [], 'address': '博学路附近', 'poiweight': '0.193172', 'name': '中山大学南方学院教学楼10号', 'location': '113.680125,23.633492', 'distance': '132.988', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B00141TQKX', 'direction': '西北', 'businessarea': [], 'address': '温泉大道882', 'poiweight': '0.148531', 'name': '中山大学南方学院教学楼6号', 'location': '113.678424,23.633710', 'distance': '153.818', 'tel': [], 'type': '科教文化服务;学校;学校'}, {'id': 'B00141WQCO', 'direction': '东北', 'businessarea': [], 'address': '博学路附近', 'poiweight': '0.14954', 'name': '中山大学南方学院教学楼8号', 'location': '113.680399,23.634329', 'distance': '225.543', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B00141TRVH', 'direction': '西南', 'businessarea': [], 'address': '博学路21', 'poiweight': '0.148531', 'name': '中山大学南方学院教学楼2号', 'location': '113.677060,23.631346', 'distance': '264.846', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B0FFKP9ET5', 'direction': '西南', 'businessarea': [], 'address': '博学路附近', 'poiweight': '0.191742', 'name': '中山大学南方学院1号实验楼', 'location': '113.678215,23.631370', 'distance': '172.86', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B00140TWHT', 'direction': '南', 'businessarea': [], 'address': '笃行路2', 'poiweight': '0.157653', 'name': '教工住宅1号', 'location': '113.678490,23.630432', 'distance': '251.758', 'tel': [], 'type': '商务住宅;住宅区;住宅小区'}, {'id': 'B0FFHC4XU0', 'direction': '南', 'businessarea': [], 'address': '温泉大道886号', 'poiweight': '0.158426', 'name': '中山大学南方学院学术交流中心', 'location': '113.679959,23.630496', 'distance': '241.095', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B0FFLBEOND', 'direction': '东南', 'businessarea': [], 'address': [], 'poiweight': '0.190963', 'name': '聚贤楼10号', 'location': '113.681253,23.631036', 'distance': '263.444', 'tel': [], 'type': '商务住宅;住宅区;宿舍'}, {'id': 'B0FFHJFHVN', 'direction': '北', 'businessarea': [], 'address': '温泉镇温泉大道', 'poiweight': '0.210336', 'name': '中山大学南方学院第五食堂', 'location': '113.679234,23.634647', 'distance': '230.464', 'tel': [], 'type': '餐饮服务;中餐厅;中餐厅'}, {'id': 'B0FFJLW0O9', 'direction': '西', 'businessarea': [], 'address': '博学路4附近', 'poiweight': '0.191645', 'name': '中山大学南方学院西区饭堂', 'location': '113.676210,23.632177', 'distance': '316.572', 'tel': [], 'type': '科教文化服务;科教文化场所;科教文化场所'}, {'id': 'B0FFJBZLYT', 'direction': '西北', 'businessarea': [], 'address': '中山路与博学路交叉口东南50米', 'poiweight': '0.297382', 'name': '铜像广场', 'location': '113.676921,23.634555', 'distance': '326.444', 'tel': [], 'type': '风景名胜;风景名胜;风景名胜'}, {'id': 'B0FFG8CSEK', 'direction': '东', 'businessarea': [], 'address': '温泉镇', 'poiweight': '0.185371', 'name': 'L5员工宿舍', 'location': '113.682583,23.631487', 'distance': '356.923', 'tel': [], 'type': '商务住宅;住宅区;宿舍'}, {'id': 'B0FFKPXO2S', 'direction': '北', 'businessarea': [], 'address': '博学路附近', 'poiweight': '0.188247', 'name': '中山大学南方学院医务室', 'location': '113.679394,23.635924', 'distance': '372.556', 'tel': [], 'type': '医疗保健服务;医疗保健服务场所;医疗保健服务场所'}, {'id': 'B0FFHHLMF8', 'direction': '东北', 'businessarea': [], 'address': '中山大学南方学院明辩路2号第三饭堂', 'poiweight': '0.178935', 'name': '茗语轩餐厅', 'location': '113.681901,23.634495', 'distance': '341.332', 'tel': '13929501395', 'type': '餐饮服务;中餐厅;中餐厅'}, {'id': 'B0FFGXGN3K', 'direction': '东', 'businessarea': [], 'address': [], 'poiweight': '0.188657', 'name': '中山大学南方学院宿舍H25', 'location': '113.683474,23.632020', 'distance': '430.984', 'tel': [], 'type': '商务住宅;住宅区;宿舍'}, {'id': 'B0FFGQ2UG9', 'direction': '东', 'businessarea': [], 'address': '温泉镇', 'poiweight': '0.189884', 'name': 'H23学生宿舍楼', 'location': '113.684021,23.633311', 'distance': '489.185', 'tel': [], 'type': '商务住宅;住宅区;宿舍'}, {'id': 'B0FFGBBC19', 'direction': '东', 'businessarea': [], 'address': '温泉镇', 'poiweight': '0.2587', 'name': '保利桃花源', 'location': '113.685212,23.633333', 'distance': '609.461', 'tel': '020-37918888', 'type': '商务住宅;住宅区;别墅'}, {'id': 'B00140U844', 'direction': '西南', 'businessarea': [], 'address': '博学路24', 'poiweight': '0.203285', 'name': '学生宿舍H-5', 'location': '113.677267,23.629149', 'distance': '433.01', 'tel': [], 'type': '地名地址信息;门牌信息;楼栋号'}, {'id': 'B0FFKQ210C', 'direction': '北', 'businessarea': [], 'address': [], 'poiweight': '0.218258', 'name': '中山大学南方学院聚贤楼7号', 'location': '113.680958,23.636938', 'distance': '514.173', 'tel': [], 'type': '商务住宅;商务住宅相关;商务住宅相关'}, {'id': 'B0FFHVQGBY', 'direction': '南', 'businessarea': [], 'address': [], 'poiweight': '0.170485', 'name': '广州市从化温泉塔洛灯商店', 'location': '113.680212,23.627906', 'distance': '527.663', 'tel': [], 'type': '购物服务;家居建材市场;家居建材市场'}, {'id': 'B0FFLJV95W', 'direction': '东北', 'businessarea': [], 'address': [], 'poiweight': '0.28899', 'name': '中山大学南方学院12BLOCK', 'location': '113.682608,23.636598', 'distance': '560.894', 'tel': [], 'type': '科教文化服务;学校;高等院校'}, {'id': 'B0FFGF9WTH', 'direction': '东北', 'businessarea': [], 'address': '从化区', 'poiweight': '0.196592', 'name': '田螺山隧道', 'location': '113.683736,23.638949', 'distance': '841.305', 'tel': [], 'type': '地名地址信息;交通地名;隧道'}]}, 'info': 'OK', 'infocode': '10000'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>status</th>\n",
       "      <th>info</th>\n",
       "      <th>infocode</th>\n",
       "      <th>regeocode.roads</th>\n",
       "      <th>regeocode.roadinters</th>\n",
       "      <th>regeocode.formatted_address</th>\n",
       "      <th>regeocode.addressComponent.city</th>\n",
       "      <th>regeocode.addressComponent.province</th>\n",
       "      <th>regeocode.addressComponent.adcode</th>\n",
       "      <th>regeocode.addressComponent.district</th>\n",
       "      <th>...</th>\n",
       "      <th>regeocode.addressComponent.country</th>\n",
       "      <th>regeocode.addressComponent.township</th>\n",
       "      <th>regeocode.addressComponent.businessAreas</th>\n",
       "      <th>regeocode.addressComponent.building.name</th>\n",
       "      <th>regeocode.addressComponent.building.type</th>\n",
       "      <th>regeocode.addressComponent.neighborhood.name</th>\n",
       "      <th>regeocode.addressComponent.neighborhood.type</th>\n",
       "      <th>regeocode.addressComponent.citycode</th>\n",
       "      <th>regeocode.aois</th>\n",
       "      <th>regeocode.pois</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>[{'id': '020F49F0050461203', 'location': '113....</td>\n",
       "      <td>[{'second_name': '中山路', 'first_id': '020F49F00...</td>\n",
       "      <td>广东省广州市从化区温泉镇中山大学南方学院</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广东省</td>\n",
       "      <td>440117</td>\n",
       "      <td>从化区</td>\n",
       "      <td>...</td>\n",
       "      <td>中国</td>\n",
       "      <td>温泉镇</td>\n",
       "      <td>[[]]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>020</td>\n",
       "      <td>[{'area': '536585.849985', 'type': '141201', '...</td>\n",
       "      <td>[{'id': 'B00140MR9A', 'direction': '西', 'busin...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  status info infocode                                    regeocode.roads  \\\n",
       "0      1   OK    10000  [{'id': '020F49F0050461203', 'location': '113....   \n",
       "\n",
       "                                regeocode.roadinters  \\\n",
       "0  [{'second_name': '中山路', 'first_id': '020F49F00...   \n",
       "\n",
       "  regeocode.formatted_address regeocode.addressComponent.city  \\\n",
       "0        广东省广州市从化区温泉镇中山大学南方学院                             广州市   \n",
       "\n",
       "  regeocode.addressComponent.province regeocode.addressComponent.adcode  \\\n",
       "0                                 广东省                            440117   \n",
       "\n",
       "  regeocode.addressComponent.district  ... regeocode.addressComponent.country  \\\n",
       "0                                 从化区  ...                                 中国   \n",
       "\n",
       "  regeocode.addressComponent.township  \\\n",
       "0                                 温泉镇   \n",
       "\n",
       "  regeocode.addressComponent.businessAreas  \\\n",
       "0                                     [[]]   \n",
       "\n",
       "  regeocode.addressComponent.building.name  \\\n",
       "0                                       []   \n",
       "\n",
       "  regeocode.addressComponent.building.type  \\\n",
       "0                                       []   \n",
       "\n",
       "  regeocode.addressComponent.neighborhood.name  \\\n",
       "0                                           []   \n",
       "\n",
       "  regeocode.addressComponent.neighborhood.type  \\\n",
       "0                                           []   \n",
       "\n",
       "  regeocode.addressComponent.citycode  \\\n",
       "0                                 020   \n",
       "\n",
       "                                      regeocode.aois  \\\n",
       "0  [{'area': '536585.849985', 'type': '141201', '...   \n",
       "\n",
       "                                      regeocode.pois  \n",
       "0  [{'id': 'B00140MR9A', 'direction': '西', 'busin...  \n",
       "\n",
       "[1 rows x 26 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# A-2 Extra 全部逆地理编码分析\n",
    "中大南方逆地理编码_all = regeocode(中大南方地理编码,extensions=\"all\")\n",
    "print(中大南方逆地理编码_all)\n",
    "df_中大南方逆地理编码_all = pd.json_normalize(中大南方逆地理编码_all)\n",
    "display(df_中大南方逆地理编码_all)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A-3 全部逆地理编码分析细节\n",
    "\n",
    "1. 大家先思考一个问题，你给高德的地址和他给你的，是不是它大气的多？\n",
    "2. 这些细节哪些是有用的？假设用户给你一个地址，和一定的诉求，我们是不是可以推荐一些POI地址？\n",
    "\n",
    "![](http://static.leiphone.com/uploads/new/article/740_740/201612/5860bb12da0e0.png?imageMogr2/format/jpg/quality/90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "      <th>direction</th>\n",
       "      <th>name</th>\n",
       "      <th>distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>020F49F0050461203</td>\n",
       "      <td>113.68,23.634</td>\n",
       "      <td>南</td>\n",
       "      <td>博学路</td>\n",
       "      <td>156.951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>020F49F0050462451</td>\n",
       "      <td>113.677,23.6347</td>\n",
       "      <td>东南</td>\n",
       "      <td>中山路</td>\n",
       "      <td>343.951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>020F49F006047765</td>\n",
       "      <td>113.682,23.6394</td>\n",
       "      <td>南</td>\n",
       "      <td>S29从莞深高速</td>\n",
       "      <td>807.947</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  id         location direction      name distance\n",
       "0  020F49F0050461203    113.68,23.634         南       博学路  156.951\n",
       "1  020F49F0050462451  113.677,23.6347        东南       中山路  343.951\n",
       "2   020F49F006047765  113.682,23.6394         南  S29从莞深高速  807.947"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>second_name</th>\n",
       "      <th>first_id</th>\n",
       "      <th>second_id</th>\n",
       "      <th>location</th>\n",
       "      <th>distance</th>\n",
       "      <th>first_name</th>\n",
       "      <th>direction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中山路</td>\n",
       "      <td>020F49F0050461203</td>\n",
       "      <td>020F49F0050462451</td>\n",
       "      <td>113.6767944,23.63466139</td>\n",
       "      <td>343.951</td>\n",
       "      <td>博学路</td>\n",
       "      <td>东南</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  second_name           first_id          second_id                 location  \\\n",
       "0         中山路  020F49F0050461203  020F49F0050462451  113.6767944,23.63466139   \n",
       "\n",
       "  distance first_name direction  \n",
       "0  343.951        博学路        东南  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>area</th>\n",
       "      <th>type</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536585.849985</td>\n",
       "      <td>141201</td>\n",
       "      <td>B00140MR9A</td>\n",
       "      <td>113.679262,23.632583</td>\n",
       "      <td>440117</td>\n",
       "      <td>中山大学南方学院</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            area    type          id              location  adcode      name  \\\n",
       "0  536585.849985  141201  B00140MR9A  113.679262,23.632583  440117  中山大学南方学院   \n",
       "\n",
       "  distance  \n",
       "0        0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>direction</th>\n",
       "      <th>businessarea</th>\n",
       "      <th>address</th>\n",
       "      <th>poiweight</th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "      <th>distance</th>\n",
       "      <th>tel</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>B00140MR9A</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882号</td>\n",
       "      <td>0.450402</td>\n",
       "      <td>中山大学南方学院</td>\n",
       "      <td>113.679262,23.632583</td>\n",
       "      <td>2.69979</td>\n",
       "      <td>020-61787326;020-61787333</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B0FFF2VMJ4</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道886号中山大学南方学院内</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院-综合楼</td>\n",
       "      <td>113.680117,23.631544</td>\n",
       "      <td>142.466</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;学校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B0FFFTC9PH</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.193172</td>\n",
       "      <td>中山大学南方学院教学楼10号</td>\n",
       "      <td>113.680125,23.633492</td>\n",
       "      <td>132.988</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>B00141TQKX</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院教学楼6号</td>\n",
       "      <td>113.678424,23.633710</td>\n",
       "      <td>153.818</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;学校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>B00141WQCO</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.14954</td>\n",
       "      <td>中山大学南方学院教学楼8号</td>\n",
       "      <td>113.680399,23.634329</td>\n",
       "      <td>225.543</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>B00141TRVH</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路21</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院教学楼2号</td>\n",
       "      <td>113.677060,23.631346</td>\n",
       "      <td>264.846</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>B0FFKP9ET5</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>中山大学南方学院1号实验楼</td>\n",
       "      <td>113.678215,23.631370</td>\n",
       "      <td>172.86</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B00140TWHT</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>笃行路2</td>\n",
       "      <td>0.157653</td>\n",
       "      <td>教工住宅1号</td>\n",
       "      <td>113.678490,23.630432</td>\n",
       "      <td>251.758</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;住宅小区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>B0FFHC4XU0</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道886号</td>\n",
       "      <td>0.158426</td>\n",
       "      <td>中山大学南方学院学术交流中心</td>\n",
       "      <td>113.679959,23.630496</td>\n",
       "      <td>241.095</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>B0FFLBEOND</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.190963</td>\n",
       "      <td>聚贤楼10号</td>\n",
       "      <td>113.681253,23.631036</td>\n",
       "      <td>263.444</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B0FFHJFHVN</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉镇温泉大道</td>\n",
       "      <td>0.210336</td>\n",
       "      <td>中山大学南方学院第五食堂</td>\n",
       "      <td>113.679234,23.634647</td>\n",
       "      <td>230.464</td>\n",
       "      <td>[]</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>B0FFJLW0O9</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路4附近</td>\n",
       "      <td>0.191645</td>\n",
       "      <td>中山大学南方学院西区饭堂</td>\n",
       "      <td>113.676210,23.632177</td>\n",
       "      <td>316.572</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>B0FFJBZLYT</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山路与博学路交叉口东南50米</td>\n",
       "      <td>0.297382</td>\n",
       "      <td>铜像广场</td>\n",
       "      <td>113.676921,23.634555</td>\n",
       "      <td>326.444</td>\n",
       "      <td>[]</td>\n",
       "      <td>风景名胜;风景名胜;风景名胜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>B0FFG8CSEK</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉镇</td>\n",
       "      <td>0.185371</td>\n",
       "      <td>L5员工宿舍</td>\n",
       "      <td>113.682583,23.631487</td>\n",
       "      <td>356.923</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>B0FFKPXO2S</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.188247</td>\n",
       "      <td>中山大学南方学院医务室</td>\n",
       "      <td>113.679394,23.635924</td>\n",
       "      <td>372.556</td>\n",
       "      <td>[]</td>\n",
       "      <td>医疗保健服务;医疗保健服务场所;医疗保健服务场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>B0FFHHLMF8</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山大学南方学院明辩路2号第三饭堂</td>\n",
       "      <td>0.178935</td>\n",
       "      <td>茗语轩餐厅</td>\n",
       "      <td>113.681901,23.634495</td>\n",
       "      <td>341.332</td>\n",
       "      <td>13929501395</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>B0FFGXGN3K</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.188657</td>\n",
       "      <td>中山大学南方学院宿舍H25</td>\n",
       "      <td>113.683474,23.632020</td>\n",
       "      <td>430.984</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>B0FFGQ2UG9</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉镇</td>\n",
       "      <td>0.189884</td>\n",
       "      <td>H23学生宿舍楼</td>\n",
       "      <td>113.684021,23.633311</td>\n",
       "      <td>489.185</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>B0FFGBBC19</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉镇</td>\n",
       "      <td>0.2587</td>\n",
       "      <td>保利桃花源</td>\n",
       "      <td>113.685212,23.633333</td>\n",
       "      <td>609.461</td>\n",
       "      <td>020-37918888</td>\n",
       "      <td>商务住宅;住宅区;别墅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>B00140U844</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路24</td>\n",
       "      <td>0.203285</td>\n",
       "      <td>学生宿舍H-5</td>\n",
       "      <td>113.677267,23.629149</td>\n",
       "      <td>433.01</td>\n",
       "      <td>[]</td>\n",
       "      <td>地名地址信息;门牌信息;楼栋号</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>B0FFKQ210C</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.218258</td>\n",
       "      <td>中山大学南方学院聚贤楼7号</td>\n",
       "      <td>113.680958,23.636938</td>\n",
       "      <td>514.173</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;商务住宅相关;商务住宅相关</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>B0FFHVQGBY</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.170485</td>\n",
       "      <td>广州市从化温泉塔洛灯商店</td>\n",
       "      <td>113.680212,23.627906</td>\n",
       "      <td>527.663</td>\n",
       "      <td>[]</td>\n",
       "      <td>购物服务;家居建材市场;家居建材市场</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>B0FFLJV95W</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.28899</td>\n",
       "      <td>中山大学南方学院12BLOCK</td>\n",
       "      <td>113.682608,23.636598</td>\n",
       "      <td>560.894</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>B0FFGF9WTH</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>0.196592</td>\n",
       "      <td>田螺山隧道</td>\n",
       "      <td>113.683736,23.638949</td>\n",
       "      <td>841.305</td>\n",
       "      <td>[]</td>\n",
       "      <td>地名地址信息;交通地名;隧道</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id direction businessarea            address poiweight  \\\n",
       "0   B00140MR9A         西           []           温泉大道882号  0.450402   \n",
       "1   B0FFF2VMJ4        东南           []  温泉大道886号中山大学南方学院内  0.148531   \n",
       "2   B0FFFTC9PH        东北           []              博学路附近  0.193172   \n",
       "3   B00141TQKX        西北           []            温泉大道882  0.148531   \n",
       "4   B00141WQCO        东北           []              博学路附近   0.14954   \n",
       "5   B00141TRVH        西南           []              博学路21  0.148531   \n",
       "6   B0FFKP9ET5        西南           []              博学路附近  0.191742   \n",
       "7   B00140TWHT         南           []               笃行路2  0.157653   \n",
       "8   B0FFHC4XU0         南           []           温泉大道886号  0.158426   \n",
       "9   B0FFLBEOND        东南           []                 []  0.190963   \n",
       "10  B0FFHJFHVN         北           []            温泉镇温泉大道  0.210336   \n",
       "11  B0FFJLW0O9         西           []             博学路4附近  0.191645   \n",
       "12  B0FFJBZLYT        西北           []    中山路与博学路交叉口东南50米  0.297382   \n",
       "13  B0FFG8CSEK         东           []                温泉镇  0.185371   \n",
       "14  B0FFKPXO2S         北           []              博学路附近  0.188247   \n",
       "15  B0FFHHLMF8        东北           []  中山大学南方学院明辩路2号第三饭堂  0.178935   \n",
       "16  B0FFGXGN3K         东           []                 []  0.188657   \n",
       "17  B0FFGQ2UG9         东           []                温泉镇  0.189884   \n",
       "18  B0FFGBBC19         东           []                温泉镇    0.2587   \n",
       "19  B00140U844        西南           []              博学路24  0.203285   \n",
       "20  B0FFKQ210C         北           []                 []  0.218258   \n",
       "21  B0FFHVQGBY         南           []                 []  0.170485   \n",
       "22  B0FFLJV95W        东北           []                 []   0.28899   \n",
       "23  B0FFGF9WTH        东北           []                从化区  0.196592   \n",
       "\n",
       "               name              location distance                        tel  \\\n",
       "0          中山大学南方学院  113.679262,23.632583  2.69979  020-61787326;020-61787333   \n",
       "1      中山大学南方学院-综合楼  113.680117,23.631544  142.466                         []   \n",
       "2    中山大学南方学院教学楼10号  113.680125,23.633492  132.988                         []   \n",
       "3     中山大学南方学院教学楼6号  113.678424,23.633710  153.818                         []   \n",
       "4     中山大学南方学院教学楼8号  113.680399,23.634329  225.543                         []   \n",
       "5     中山大学南方学院教学楼2号  113.677060,23.631346  264.846                         []   \n",
       "6     中山大学南方学院1号实验楼  113.678215,23.631370   172.86                         []   \n",
       "7            教工住宅1号  113.678490,23.630432  251.758                         []   \n",
       "8    中山大学南方学院学术交流中心  113.679959,23.630496  241.095                         []   \n",
       "9            聚贤楼10号  113.681253,23.631036  263.444                         []   \n",
       "10     中山大学南方学院第五食堂  113.679234,23.634647  230.464                         []   \n",
       "11     中山大学南方学院西区饭堂  113.676210,23.632177  316.572                         []   \n",
       "12             铜像广场  113.676921,23.634555  326.444                         []   \n",
       "13           L5员工宿舍  113.682583,23.631487  356.923                         []   \n",
       "14      中山大学南方学院医务室  113.679394,23.635924  372.556                         []   \n",
       "15            茗语轩餐厅  113.681901,23.634495  341.332                13929501395   \n",
       "16    中山大学南方学院宿舍H25  113.683474,23.632020  430.984                         []   \n",
       "17         H23学生宿舍楼  113.684021,23.633311  489.185                         []   \n",
       "18            保利桃花源  113.685212,23.633333  609.461               020-37918888   \n",
       "19          学生宿舍H-5  113.677267,23.629149   433.01                         []   \n",
       "20    中山大学南方学院聚贤楼7号  113.680958,23.636938  514.173                         []   \n",
       "21     广州市从化温泉塔洛灯商店  113.680212,23.627906  527.663                         []   \n",
       "22  中山大学南方学院12BLOCK  113.682608,23.636598  560.894                         []   \n",
       "23            田螺山隧道  113.683736,23.638949  841.305                         []   \n",
       "\n",
       "                        type  \n",
       "0             科教文化服务;学校;高等院校  \n",
       "1               科教文化服务;学校;学校  \n",
       "2       科教文化服务;科教文化场所;科教文化场所  \n",
       "3               科教文化服务;学校;学校  \n",
       "4       科教文化服务;科教文化场所;科教文化场所  \n",
       "5       科教文化服务;科教文化场所;科教文化场所  \n",
       "6       科教文化服务;科教文化场所;科教文化场所  \n",
       "7              商务住宅;住宅区;住宅小区  \n",
       "8       科教文化服务;科教文化场所;科教文化场所  \n",
       "9                商务住宅;住宅区;宿舍  \n",
       "10              餐饮服务;中餐厅;中餐厅  \n",
       "11      科教文化服务;科教文化场所;科教文化场所  \n",
       "12            风景名胜;风景名胜;风景名胜  \n",
       "13               商务住宅;住宅区;宿舍  \n",
       "14  医疗保健服务;医疗保健服务场所;医疗保健服务场所  \n",
       "15              餐饮服务;中餐厅;中餐厅  \n",
       "16               商务住宅;住宅区;宿舍  \n",
       "17               商务住宅;住宅区;宿舍  \n",
       "18               商务住宅;住宅区;别墅  \n",
       "19           地名地址信息;门牌信息;楼栋号  \n",
       "20        商务住宅;商务住宅相关;商务住宅相关  \n",
       "21        购物服务;家居建材市场;家居建材市场  \n",
       "22            科教文化服务;学校;高等院校  \n",
       "23            地名地址信息;交通地名;隧道  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# A-3 分析细节\n",
    "roads = pd.json_normalize(中大南方逆地理编码_all['regeocode']['roads'])\n",
    "roadinters = pd.json_normalize(中大南方逆地理编码_all['regeocode']['roadinters'])\n",
    "aois = pd.json_normalize(中大南方逆地理编码_all['regeocode']['aois'])\n",
    "pois = pd.json_normalize(中大南方逆地理编码_all['regeocode']['pois'])\n",
    "display(roads,roadinters,aois,pois)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 学生练习：\n",
    "1. 观察和练习其他参数\n",
    "2. 想得到更大范围的搜索POI如何操作\n",
    "3. * 请pandas学过的同学对address进行分组groupby练习，尝试找寻不同根类地址下的type（可选用你所找寻的地址，不一定用中大南方）\n",
    "4. * 请思考如何对不同类型的服务进行分类？如美食、旅馆、加油站...等\n",
    "![](lianxi01.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 路径规划（点到点的过程）  \n",
    "\n",
    "\n",
    "### 产品的设计思维 \n",
    "\n",
    "1. 请思考，什么样的产品需要路径规划？\n",
    "2. 如果你的产品需要，你会如何使用？\n",
    "3. 最优路线如何选择？高德会用到什么算法？（推荐系统）\n",
    "    1. 推荐系统输入location么？（起点、终点？还是全部点？）\n",
    "    2. 实时的定位？（多长时间定位一次）更新1\n",
    "    3. 定位完成其他点的变化？距离的选择（用户希望路边有更多的需求还是希望快速找到目的地？）\n",
    "    4. 以上思考的越多，你的产品考虑的会越周全，避免产品后期的大量更改。\n",
    "    \n",
    "4. 可能了解的知识面，不需要清楚怎么做，但可以了解输入输出的结果是什么。参考如下图\n",
    "\n",
    "![](http://imgtec.eetrend.com/files/2019-03/%E5%8D%9A%E5%AE%A2/100018447-63696-10.jpg)\n",
    "\n",
    "-----\n",
    "![](https://pic2.zhimg.com/50/v2-45a26a9985308d90405dea78e6892dd0_r.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 步行路径规划（API基本流程）（代码B）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### B-1 准备base url、params、response.json（） "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "# B-1 准备base url、params、response.json（） \n",
    "def walking(origin,destination,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key_xu,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### B-2 准备walking 参数\n",
    "\n",
    "请同学们尝试从A-3细节中获取的某两个教学楼的location，尝试步行路径规划（起点）🙅----->（终点）🙅‍"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)中大南方_location: 113.679287,23.632575 (终点)龙岗社区居委会_location: 113.669129,23.600956\n"
     ]
    }
   ],
   "source": [
    "# B-2 准备walking 参数\n",
    "龙岗社区居委会 = geocode('广东省广州市从化区龙岗社区居委会')\n",
    "龙岗社区居委会_location = 龙岗社区居委会['geocodes'][0]['location']\n",
    "中大南方_location = 中大南方['geocodes'][0]['location']\n",
    "print(\"(起点)中大南方_location:\",中大南方_location,\"(终点)龙岗社区居委会_location:\",龙岗社区居委会_location)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### B-3 实现步行路径规划"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>walk_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向南步行161米右转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>161</td>\n",
       "      <td>129</td>\n",
       "      <td>113.679592,23.632088;113.679609,23.631003;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向西步行99米左转</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>99</td>\n",
       "      <td>79</td>\n",
       "      <td>113.67964,23.630634;113.679362,23.630521;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>向南步行237米左转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>237</td>\n",
       "      <td>190</td>\n",
       "      <td>113.678711,23.63036;113.678711,23.62934;113.67...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>向南步行498米向右前方行走</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>498</td>\n",
       "      <td>398</td>\n",
       "      <td>113.678273,23.628368;113.678572,23.628338;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向西南步行715米左转</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>715</td>\n",
       "      <td>572</td>\n",
       "      <td>113.678572,23.624653;113.678559,23.62451;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>向东南步行406米向右前方行走</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>406</td>\n",
       "      <td>325</td>\n",
       "      <td>113.675299,23.620048;113.675642,23.619991;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>沿乌土街向南步行1380米右转</td>\n",
       "      <td>南</td>\n",
       "      <td>乌土街</td>\n",
       "      <td>1380</td>\n",
       "      <td>1104</td>\n",
       "      <td>113.678181,23.617652;113.678095,23.617205;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>沿乌土街向西南步行165米直行</td>\n",
       "      <td>西南</td>\n",
       "      <td>乌土街</td>\n",
       "      <td>165</td>\n",
       "      <td>132</td>\n",
       "      <td>113.677535,23.605668;113.676988,23.605373;113....</td>\n",
       "      <td>直行</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>沿934县道向西步行118米直行</td>\n",
       "      <td>西</td>\n",
       "      <td>934县道</td>\n",
       "      <td>118</td>\n",
       "      <td>94</td>\n",
       "      <td>113.676159,23.604883;113.675929,23.604831;113....</td>\n",
       "      <td>直行</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>沿桃园东路向西南步行673米向右前方行走</td>\n",
       "      <td>西南</td>\n",
       "      <td>桃园东路</td>\n",
       "      <td>673</td>\n",
       "      <td>538</td>\n",
       "      <td>113.675009,23.604735;113.674236,23.604683;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>沿桃园东路向西南步行117米到达目的地</td>\n",
       "      <td>西南</td>\n",
       "      <td>桃园东路</td>\n",
       "      <td>117</td>\n",
       "      <td>94</td>\n",
       "      <td>113.669714,23.601897;113.66964,23.601771;113.6...</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             instruction orientation   road distance duration  \\\n",
       "0             向南步行161米右转           南     []      161      129   \n",
       "1              向西步行99米左转           西     []       99       79   \n",
       "2             向南步行237米左转           南     []      237      190   \n",
       "3         向南步行498米向右前方行走           南     []      498      398   \n",
       "4            向西南步行715米左转          西南     []      715      572   \n",
       "5        向东南步行406米向右前方行走          东南     []      406      325   \n",
       "6        沿乌土街向南步行1380米右转           南    乌土街     1380     1104   \n",
       "7        沿乌土街向西南步行165米直行          西南    乌土街      165      132   \n",
       "8       沿934县道向西步行118米直行           西  934县道      118       94   \n",
       "9   沿桃园东路向西南步行673米向右前方行走          西南   桃园东路      673      538   \n",
       "10   沿桃园东路向西南步行117米到达目的地          西南   桃园东路      117       94   \n",
       "\n",
       "                                             polyline  action  \\\n",
       "0   113.679592,23.632088;113.679609,23.631003;113....      右转   \n",
       "1   113.67964,23.630634;113.679362,23.630521;113.6...      左转   \n",
       "2   113.678711,23.63036;113.678711,23.62934;113.67...      左转   \n",
       "3   113.678273,23.628368;113.678572,23.628338;113....  向右前方行走   \n",
       "4   113.678572,23.624653;113.678559,23.62451;113.6...      左转   \n",
       "5   113.675299,23.620048;113.675642,23.619991;113....  向右前方行走   \n",
       "6   113.678181,23.617652;113.678095,23.617205;113....      右转   \n",
       "7   113.677535,23.605668;113.676988,23.605373;113....      直行   \n",
       "8   113.676159,23.604883;113.675929,23.604831;113....      直行   \n",
       "9   113.675009,23.604735;113.674236,23.604683;113....  向右前方行走   \n",
       "10  113.669714,23.601897;113.66964,23.601771;113.6...      []   \n",
       "\n",
       "   assistant_action walk_type  \n",
       "0                []         0  \n",
       "1                []         0  \n",
       "2                []         0  \n",
       "3                []         0  \n",
       "4                []         0  \n",
       "5                []         0  \n",
       "6                []         0  \n",
       "7                []         0  \n",
       "8                []         0  \n",
       "9                []         0  \n",
       "10            到达目的地         0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0               向南步行161米右转\n",
       "1                向西步行99米左转\n",
       "2               向南步行237米左转\n",
       "3           向南步行498米向右前方行走\n",
       "4              向西南步行715米左转\n",
       "5          向东南步行406米向右前方行走\n",
       "6          沿乌土街向南步行1380米右转\n",
       "7          沿乌土街向西南步行165米直行\n",
       "8         沿934县道向西步行118米直行\n",
       "9     沿桃园东路向西南步行673米向右前方行走\n",
       "10     沿桃园东路向西南步行117米到达目的地\n",
       "Name: instruction, dtype: object"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# B-3 路径规划\n",
    "中大南方_龙岗社区居委会 = walking(中大南方_location,龙岗社区居委会_location)\n",
    "df_步行路径规划 = pd.json_normalize(中大南方_龙岗社区居委会[\"route\"][\"paths\"][0]['steps'])\n",
    "display(df_步行路径规划)\n",
    "df_步行路径规划[\"instruction\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 学生练习（请换用其他地址满足以下要求）\n",
    "\n",
    "1. 请更换地址，选择尽量含有walk_type参数，并查看高德是否返回正确\n",
    "2. 尝试不同的地址，检查返回的json\n",
    "\n",
    "\n",
    "![](lianxi02.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 公交路线规划（代码C）\n",
    "\n",
    "1. 请同学们细读可使用的参数\n",
    "2. 尝试更改参数带到你想要的目标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)中山大学_location: 113.290219,23.128596 (终点)中大南方_location: 113.361200,23.124680\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>status</th>\n",
       "      <th>info</th>\n",
       "      <th>infocode</th>\n",
       "      <th>count</th>\n",
       "      <th>route.origin</th>\n",
       "      <th>route.destination</th>\n",
       "      <th>route.distance</th>\n",
       "      <th>route.taxi_cost</th>\n",
       "      <th>route.transits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>OK</td>\n",
       "      <td>10000</td>\n",
       "      <td>5</td>\n",
       "      <td>113.290219,23.128596</td>\n",
       "      <td>113.361200,23.124680</td>\n",
       "      <td>7012</td>\n",
       "      <td>21.7312</td>\n",
       "      <td>[{'cost': '2.0', 'duration': '2238', 'nightfla...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  status info infocode count          route.origin     route.destination  \\\n",
       "0      1   OK    10000     5  113.290219,23.128596  113.361200,23.124680   \n",
       "\n",
       "  route.distance route.taxi_cost  \\\n",
       "0           7012         21.7312   \n",
       "\n",
       "                                      route.transits  \n",
       "0  [{'cost': '2.0', 'duration': '2238', 'nightfla...  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# C-1\n",
    "def integrated(origin,destination,city,cityd=None,extensions='base',strategy=None,nightflag=0,date=None,time=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'\n",
    "    params={\n",
    "        'key':key_xu,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'city':city,\n",
    "        'cityd':cityd,\n",
    "        'extensions':extensions,\n",
    "        'strategy':strategy,\n",
    "        'nightflag':nightflag,\n",
    "        'date':date,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "# C-2 准备walking 参数\n",
    "中山大学 = geocode('广东省广州市中山大学南校区')\n",
    "中山大学_location = 中山大学['geocodes'][0]['location']\n",
    "天河城 = geocode('广东省广州市天河城')\n",
    "天河城_location = 天河城['geocodes'][0]['location']\n",
    "print(\"(起点)中山大学_location:\",中山大学_location,\"(终点)中大南方_location:\",天河城_location)\n",
    "\n",
    "# C-3 公交路径规划\n",
    "中大_天河城 = integrated(中山大学_location,天河城_location,city='广州',extensions='all')\n",
    "df_bus = pd.json_normalize(中大_天河城)\n",
    "df_bus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cost</th>\n",
       "      <th>duration</th>\n",
       "      <th>nightflag</th>\n",
       "      <th>walking_distance</th>\n",
       "      <th>distance</th>\n",
       "      <th>missed</th>\n",
       "      <th>segments</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2238</td>\n",
       "      <td>0</td>\n",
       "      <td>1138</td>\n",
       "      <td>7823</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'taxi': [], 'walking': {'origin': '113.29036...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2557</td>\n",
       "      <td>0</td>\n",
       "      <td>979</td>\n",
       "      <td>8224</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'taxi': [], 'walking': {'origin': '113.29036...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.0</td>\n",
       "      <td>2442</td>\n",
       "      <td>0</td>\n",
       "      <td>1689</td>\n",
       "      <td>10344</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'taxi': [], 'walking': {'origin': '113.29036...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2693</td>\n",
       "      <td>0</td>\n",
       "      <td>965</td>\n",
       "      <td>8551</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'taxi': [], 'walking': {'origin': '113.29036...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.0</td>\n",
       "      <td>2974</td>\n",
       "      <td>0</td>\n",
       "      <td>795</td>\n",
       "      <td>14206</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'taxi': [], 'walking': {'origin': '113.29036...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  cost duration nightflag walking_distance distance missed  \\\n",
       "0  2.0     2238         0             1138     7823      1   \n",
       "1  2.0     2557         0              979     8224      1   \n",
       "2  4.0     2442         0             1689    10344      1   \n",
       "3  2.0     2693         0              965     8551      1   \n",
       "4  2.0     2974         0              795    14206      1   \n",
       "\n",
       "                                            segments  \n",
       "0  [{'taxi': [], 'walking': {'origin': '113.29036...  \n",
       "1  [{'taxi': [], 'walking': {'origin': '113.29036...  \n",
       "2  [{'taxi': [], 'walking': {'origin': '113.29036...  \n",
       "3  [{'taxi': [], 'walking': {'origin': '113.29036...  \n",
       "4  [{'taxi': [], 'walking': {'origin': '113.29036...  "
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(中大_天河城[\"route\"]['transits'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>taxi</th>\n",
       "      <th>entrance</th>\n",
       "      <th>exit</th>\n",
       "      <th>walking.origin</th>\n",
       "      <th>walking.destination</th>\n",
       "      <th>walking.distance</th>\n",
       "      <th>walking.duration</th>\n",
       "      <th>walking.steps</th>\n",
       "      <th>bus.buslines</th>\n",
       "      <th>railway.via_stops</th>\n",
       "      <th>railway.alters</th>\n",
       "      <th>railway.spaces</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.290367,23.128555</td>\n",
       "      <td>113.293068,23.130842</td>\n",
       "      <td>495</td>\n",
       "      <td>424</td>\n",
       "      <td>[{'instruction': '沿岭南路步行139米右转', 'road': '岭南路'...</td>\n",
       "      <td>[{'departure_stop': {'name': '执信路', 'id': '900...</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.357956,23.124006</td>\n",
       "      <td>113.361488,23.124657</td>\n",
       "      <td>643</td>\n",
       "      <td>551</td>\n",
       "      <td>[{'instruction': '沿黄埔大道中步行120米靠右', 'road': '黄埔...</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  taxi entrance exit        walking.origin   walking.destination  \\\n",
       "0   []       []   []  113.290367,23.128555  113.293068,23.130842   \n",
       "1   []       []   []  113.357956,23.124006  113.361488,23.124657   \n",
       "\n",
       "  walking.distance walking.duration  \\\n",
       "0              495              424   \n",
       "1              643              551   \n",
       "\n",
       "                                       walking.steps  \\\n",
       "0  [{'instruction': '沿岭南路步行139米右转', 'road': '岭南路'...   \n",
       "1  [{'instruction': '沿黄埔大道中步行120米靠右', 'road': '黄埔...   \n",
       "\n",
       "                                        bus.buslines railway.via_stops  \\\n",
       "0  [{'departure_stop': {'name': '执信路', 'id': '900...                []   \n",
       "1                                                 []                []   \n",
       "\n",
       "  railway.alters railway.spaces  \n",
       "0             []             []  \n",
       "1             []             []  "
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(中大_天河城[\"route\"]['transits'][0]['segments'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "      <th>type</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>bustimetag</th>\n",
       "      <th>start_time</th>\n",
       "      <th>end_time</th>\n",
       "      <th>via_num</th>\n",
       "      <th>via_stops</th>\n",
       "      <th>departure_stop.name</th>\n",
       "      <th>departure_stop.id</th>\n",
       "      <th>departure_stop.location</th>\n",
       "      <th>arrival_stop.name</th>\n",
       "      <th>arrival_stop.id</th>\n",
       "      <th>arrival_stop.location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>高峰快线23路(南岸路--员村四横路口)</td>\n",
       "      <td>900000028901</td>\n",
       "      <td>普通公交线路</td>\n",
       "      <td>6685</td>\n",
       "      <td>1263</td>\n",
       "      <td>113.293137,23.130842;113.293152,23.130842;113....</td>\n",
       "      <td>2</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>5</td>\n",
       "      <td>[{'name': '东风东路站', 'id': '900000028901010', 'l...</td>\n",
       "      <td>执信路</td>\n",
       "      <td>900000028901009</td>\n",
       "      <td>113.293137,23.130842</td>\n",
       "      <td>员村山顶</td>\n",
       "      <td>900000028901015</td>\n",
       "      <td>113.357964,23.124006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>284路(广园新村总站--员村总站)</td>\n",
       "      <td>440100016471</td>\n",
       "      <td>普通公交线路</td>\n",
       "      <td>6936</td>\n",
       "      <td>1558</td>\n",
       "      <td>113.293060,23.130842;113.293152,23.130842;113....</td>\n",
       "      <td>2</td>\n",
       "      <td>0600</td>\n",
       "      <td>2220</td>\n",
       "      <td>8</td>\n",
       "      <td>[{'name': '东风东路站', 'id': '440100016471014', 'l...</td>\n",
       "      <td>执信路</td>\n",
       "      <td>440100016471013</td>\n",
       "      <td>113.293060,23.130842</td>\n",
       "      <td>员村山顶</td>\n",
       "      <td>440100016471022</td>\n",
       "      <td>113.358780,23.123848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>518路(站前路总站--棠下小区总站)</td>\n",
       "      <td>440100016786</td>\n",
       "      <td>普通公交线路</td>\n",
       "      <td>7427</td>\n",
       "      <td>1647</td>\n",
       "      <td>113.293091,23.130842;113.293152,23.130842;113....</td>\n",
       "      <td>2</td>\n",
       "      <td>0615</td>\n",
       "      <td>2230</td>\n",
       "      <td>8</td>\n",
       "      <td>[{'name': '东风东路站', 'id': '440100016786016', 'l...</td>\n",
       "      <td>执信路</td>\n",
       "      <td>440100016786015</td>\n",
       "      <td>113.293091,23.130842</td>\n",
       "      <td>员村山顶</td>\n",
       "      <td>440100016786025</td>\n",
       "      <td>113.357979,23.124002</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   name            id    type distance duration  \\\n",
       "0  高峰快线23路(南岸路--员村四横路口)  900000028901  普通公交线路     6685     1263   \n",
       "1    284路(广园新村总站--员村总站)  440100016471  普通公交线路     6936     1558   \n",
       "2   518路(站前路总站--棠下小区总站)  440100016786  普通公交线路     7427     1647   \n",
       "\n",
       "                                            polyline bustimetag start_time  \\\n",
       "0  113.293137,23.130842;113.293152,23.130842;113....          2         []   \n",
       "1  113.293060,23.130842;113.293152,23.130842;113....          2       0600   \n",
       "2  113.293091,23.130842;113.293152,23.130842;113....          2       0615   \n",
       "\n",
       "  end_time via_num                                          via_stops  \\\n",
       "0       []       5  [{'name': '东风东路站', 'id': '900000028901010', 'l...   \n",
       "1     2220       8  [{'name': '东风东路站', 'id': '440100016471014', 'l...   \n",
       "2     2230       8  [{'name': '东风东路站', 'id': '440100016786016', 'l...   \n",
       "\n",
       "  departure_stop.name departure_stop.id departure_stop.location  \\\n",
       "0                 执信路   900000028901009    113.293137,23.130842   \n",
       "1                 执信路   440100016471013    113.293060,23.130842   \n",
       "2                 执信路   440100016786015    113.293091,23.130842   \n",
       "\n",
       "  arrival_stop.name  arrival_stop.id arrival_stop.location  \n",
       "0              员村山顶  900000028901015  113.357964,23.124006  \n",
       "1              员村山顶  440100016471022  113.358780,23.123848  \n",
       "2              员村山顶  440100016786025  113.357979,23.124002  "
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_bus_基本信息 = pd.json_normalize(中大_天河城[\"route\"]['transits'][0]['segments'][0]['bus'][\"buslines\"])\n",
    "df_bus_基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_23路公交车</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东风东路站</td>\n",
       "      <td>900000028901010</td>\n",
       "      <td>113.303528,23.131758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东峻广场</td>\n",
       "      <td>900000028901011</td>\n",
       "      <td>113.306824,23.131800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>石牌村</td>\n",
       "      <td>900000028901012</td>\n",
       "      <td>113.339638,23.126385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>国防大厦</td>\n",
       "      <td>900000028901013</td>\n",
       "      <td>113.345024,23.125916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>华侨医院(潭村)</td>\n",
       "      <td>900000028901014</td>\n",
       "      <td>113.352211,23.124826</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    _23路公交车               id              location\n",
       "0     东风东路站  900000028901010  113.303528,23.131758\n",
       "1      东峻广场  900000028901011  113.306824,23.131800\n",
       "2       石牌村  900000028901012  113.339638,23.126385\n",
       "3      国防大厦  900000028901013  113.345024,23.125916\n",
       "4  华侨医院(潭村)  900000028901014  113.352211,23.124826"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_284路公交车</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东风东路站</td>\n",
       "      <td>440100016471014</td>\n",
       "      <td>113.303474,23.131762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东峻广场</td>\n",
       "      <td>440100016471015</td>\n",
       "      <td>113.306816,23.131800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>锦城花园</td>\n",
       "      <td>440100016471029</td>\n",
       "      <td>113.310783,23.131516</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>天河</td>\n",
       "      <td>440100016471017</td>\n",
       "      <td>113.319405,23.127560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>冼村</td>\n",
       "      <td>440100016471018</td>\n",
       "      <td>113.330666,23.126894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>石牌村</td>\n",
       "      <td>440100016471019</td>\n",
       "      <td>113.340469,23.126249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>国防大厦</td>\n",
       "      <td>440100016471020</td>\n",
       "      <td>113.344879,23.125929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>华侨医院(潭村)</td>\n",
       "      <td>440100016471033</td>\n",
       "      <td>113.352188,23.124830</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   _284路公交车               id              location\n",
       "0     东风东路站  440100016471014  113.303474,23.131762\n",
       "1      东峻广场  440100016471015  113.306816,23.131800\n",
       "2      锦城花园  440100016471029  113.310783,23.131516\n",
       "3        天河  440100016471017  113.319405,23.127560\n",
       "4        冼村  440100016471018  113.330666,23.126894\n",
       "5       石牌村  440100016471019  113.340469,23.126249\n",
       "6      国防大厦  440100016471020  113.344879,23.125929\n",
       "7  华侨医院(潭村)  440100016471033  113.352188,23.124830"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_518路公交车</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东风东路站</td>\n",
       "      <td>440100016786016</td>\n",
       "      <td>113.303513,23.131758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东峻广场</td>\n",
       "      <td>440100016786017</td>\n",
       "      <td>113.306862,23.131800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>锦城花园</td>\n",
       "      <td>440100016786037</td>\n",
       "      <td>113.310692,23.131544</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>华夏路北</td>\n",
       "      <td>440100016786019</td>\n",
       "      <td>113.321175,23.126129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>冼村</td>\n",
       "      <td>440100016786021</td>\n",
       "      <td>113.329811,23.126940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>石牌村</td>\n",
       "      <td>440100016786022</td>\n",
       "      <td>113.339523,23.126389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>国防大厦</td>\n",
       "      <td>440100016786023</td>\n",
       "      <td>113.344872,23.125929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>华侨医院(潭村)</td>\n",
       "      <td>440100016786038</td>\n",
       "      <td>113.352234,23.124823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   _518路公交车               id              location\n",
       "0     东风东路站  440100016786016  113.303513,23.131758\n",
       "1      东峻广场  440100016786017  113.306862,23.131800\n",
       "2      锦城花园  440100016786037  113.310692,23.131544\n",
       "3      华夏路北  440100016786019  113.321175,23.126129\n",
       "4        冼村  440100016786021  113.329811,23.126940\n",
       "5       石牌村  440100016786022  113.339523,23.126389\n",
       "6      国防大厦  440100016786023  113.344872,23.125929\n",
       "7  华侨医院(潭村)  440100016786038  113.352234,23.124823"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_23路公交车 = pd.json_normalize(中大_天河城[\"route\"]['transits'][0]['segments'][0]['bus'][\"buslines\"][0][\"via_stops\"]).rename(columns={\"name\":\"_23路公交车\"})\n",
    "_284路公交车 = pd.json_normalize(中大_天河城[\"route\"]['transits'][0]['segments'][0]['bus'][\"buslines\"][1][\"via_stops\"]).rename(columns={\"name\":\"_284路公交车\"})\n",
    "_518路公交车 = pd.json_normalize(中大_天河城[\"route\"]['transits'][0]['segments'][0]['bus'][\"buslines\"][2][\"via_stops\"]).rename(columns={\"name\":\"_518路公交车\"})\n",
    "display(_23路公交车,_284路公交车,_518路公交车)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 行政区域查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>center</th>\n",
       "      <th>level</th>\n",
       "      <th>districts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0758</td>\n",
       "      <td>441200</td>\n",
       "      <td>肇庆市</td>\n",
       "      <td>112.472529,23.051546</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0758', 'adcode': '441224', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0757</td>\n",
       "      <td>440600</td>\n",
       "      <td>佛山市</td>\n",
       "      <td>113.122717,23.028762</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0757', 'adcode': '440607', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0754</td>\n",
       "      <td>440500</td>\n",
       "      <td>汕头市</td>\n",
       "      <td>116.708463,23.37102</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0754', 'adcode': '440513', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0752</td>\n",
       "      <td>441300</td>\n",
       "      <td>惠州市</td>\n",
       "      <td>114.412599,23.079404</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0752', 'adcode': '441324', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0755</td>\n",
       "      <td>440300</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>114.085947,22.547</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0755', 'adcode': '440306', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0756</td>\n",
       "      <td>440400</td>\n",
       "      <td>珠海市</td>\n",
       "      <td>113.553986,22.224979</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0756', 'adcode': '440402', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0759</td>\n",
       "      <td>440800</td>\n",
       "      <td>湛江市</td>\n",
       "      <td>110.364977,21.274898</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0759', 'adcode': '440883', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0662</td>\n",
       "      <td>441700</td>\n",
       "      <td>阳江市</td>\n",
       "      <td>111.975107,21.859222</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0662', 'adcode': '441781', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0660</td>\n",
       "      <td>441500</td>\n",
       "      <td>汕尾市</td>\n",
       "      <td>115.364238,22.774485</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0660', 'adcode': '441523', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0768</td>\n",
       "      <td>445100</td>\n",
       "      <td>潮州市</td>\n",
       "      <td>116.632301,23.661701</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0768', 'adcode': '445122', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0750</td>\n",
       "      <td>440700</td>\n",
       "      <td>江门市</td>\n",
       "      <td>113.094942,22.590431</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0750', 'adcode': '440784', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0766</td>\n",
       "      <td>445300</td>\n",
       "      <td>云浮市</td>\n",
       "      <td>112.044439,22.929801</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0766', 'adcode': '445322', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0767</td>\n",
       "      <td>442100</td>\n",
       "      <td>东沙群岛</td>\n",
       "      <td>116.887312,20.617512</td>\n",
       "      <td>city</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0668</td>\n",
       "      <td>440900</td>\n",
       "      <td>茂名市</td>\n",
       "      <td>110.919229,21.659751</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0668', 'adcode': '440983', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0762</td>\n",
       "      <td>441600</td>\n",
       "      <td>河源市</td>\n",
       "      <td>114.697802,23.746266</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0762', 'adcode': '441622', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0753</td>\n",
       "      <td>441400</td>\n",
       "      <td>梅州市</td>\n",
       "      <td>116.117582,24.299112</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0753', 'adcode': '441427', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0769</td>\n",
       "      <td>441900</td>\n",
       "      <td>东莞市</td>\n",
       "      <td>113.746262,23.046237</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0769', 'adcode': '441900', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0663</td>\n",
       "      <td>445200</td>\n",
       "      <td>揭阳市</td>\n",
       "      <td>116.355733,23.543778</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0663', 'adcode': '445222', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0763</td>\n",
       "      <td>441800</td>\n",
       "      <td>清远市</td>\n",
       "      <td>113.051227,23.685022</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0763', 'adcode': '441882', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0751</td>\n",
       "      <td>440200</td>\n",
       "      <td>韶关市</td>\n",
       "      <td>113.591544,24.801322</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0751', 'adcode': '440282', 'nam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>020</td>\n",
       "      <td>440100</td>\n",
       "      <td>广州市</td>\n",
       "      <td>113.280637,23.125178</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '020', 'adcode': '440117', 'name...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0760</td>\n",
       "      <td>442000</td>\n",
       "      <td>中山市</td>\n",
       "      <td>113.382391,22.521113</td>\n",
       "      <td>city</td>\n",
       "      <td>[{'citycode': '0760', 'adcode': '442000', 'nam...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   citycode  adcode  name                center level  \\\n",
       "0      0758  441200   肇庆市  112.472529,23.051546  city   \n",
       "1      0757  440600   佛山市  113.122717,23.028762  city   \n",
       "2      0754  440500   汕头市   116.708463,23.37102  city   \n",
       "3      0752  441300   惠州市  114.412599,23.079404  city   \n",
       "4      0755  440300   深圳市     114.085947,22.547  city   \n",
       "5      0756  440400   珠海市  113.553986,22.224979  city   \n",
       "6      0759  440800   湛江市  110.364977,21.274898  city   \n",
       "7      0662  441700   阳江市  111.975107,21.859222  city   \n",
       "8      0660  441500   汕尾市  115.364238,22.774485  city   \n",
       "9      0768  445100   潮州市  116.632301,23.661701  city   \n",
       "10     0750  440700   江门市  113.094942,22.590431  city   \n",
       "11     0766  445300   云浮市  112.044439,22.929801  city   \n",
       "12     0767  442100  东沙群岛  116.887312,20.617512  city   \n",
       "13     0668  440900   茂名市  110.919229,21.659751  city   \n",
       "14     0762  441600   河源市  114.697802,23.746266  city   \n",
       "15     0753  441400   梅州市  116.117582,24.299112  city   \n",
       "16     0769  441900   东莞市  113.746262,23.046237  city   \n",
       "17     0663  445200   揭阳市  116.355733,23.543778  city   \n",
       "18     0763  441800   清远市  113.051227,23.685022  city   \n",
       "19     0751  440200   韶关市  113.591544,24.801322  city   \n",
       "20      020  440100   广州市  113.280637,23.125178  city   \n",
       "21     0760  442000   中山市  113.382391,22.521113  city   \n",
       "\n",
       "                                            districts  \n",
       "0   [{'citycode': '0758', 'adcode': '441224', 'nam...  \n",
       "1   [{'citycode': '0757', 'adcode': '440607', 'nam...  \n",
       "2   [{'citycode': '0754', 'adcode': '440513', 'nam...  \n",
       "3   [{'citycode': '0752', 'adcode': '441324', 'nam...  \n",
       "4   [{'citycode': '0755', 'adcode': '440306', 'nam...  \n",
       "5   [{'citycode': '0756', 'adcode': '440402', 'nam...  \n",
       "6   [{'citycode': '0759', 'adcode': '440883', 'nam...  \n",
       "7   [{'citycode': '0662', 'adcode': '441781', 'nam...  \n",
       "8   [{'citycode': '0660', 'adcode': '441523', 'nam...  \n",
       "9   [{'citycode': '0768', 'adcode': '445122', 'nam...  \n",
       "10  [{'citycode': '0750', 'adcode': '440784', 'nam...  \n",
       "11  [{'citycode': '0766', 'adcode': '445322', 'nam...  \n",
       "12                                                 []  \n",
       "13  [{'citycode': '0668', 'adcode': '440983', 'nam...  \n",
       "14  [{'citycode': '0762', 'adcode': '441622', 'nam...  \n",
       "15  [{'citycode': '0753', 'adcode': '441427', 'nam...  \n",
       "16  [{'citycode': '0769', 'adcode': '441900', 'nam...  \n",
       "17  [{'citycode': '0663', 'adcode': '445222', 'nam...  \n",
       "18  [{'citycode': '0763', 'adcode': '441882', 'nam...  \n",
       "19  [{'citycode': '0751', 'adcode': '440282', 'nam...  \n",
       "20  [{'citycode': '020', 'adcode': '440117', 'name...  \n",
       "21  [{'citycode': '0760', 'adcode': '442000', 'nam...  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>center</th>\n",
       "      <th>level</th>\n",
       "      <th>districts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>从化区</td>\n",
       "      <td>113.587386,23.545283</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>020</td>\n",
       "      <td>440115</td>\n",
       "      <td>南沙区</td>\n",
       "      <td>113.53738,22.794531</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>020</td>\n",
       "      <td>440114</td>\n",
       "      <td>花都区</td>\n",
       "      <td>113.211184,23.39205</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>020</td>\n",
       "      <td>440113</td>\n",
       "      <td>番禺区</td>\n",
       "      <td>113.364619,22.938582</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>020</td>\n",
       "      <td>440103</td>\n",
       "      <td>荔湾区</td>\n",
       "      <td>113.243038,23.124943</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>020</td>\n",
       "      <td>440105</td>\n",
       "      <td>海珠区</td>\n",
       "      <td>113.262008,23.103131</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>020</td>\n",
       "      <td>440111</td>\n",
       "      <td>白云区</td>\n",
       "      <td>113.262831,23.162281</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>020</td>\n",
       "      <td>440118</td>\n",
       "      <td>增城区</td>\n",
       "      <td>113.829579,23.290497</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>020</td>\n",
       "      <td>440112</td>\n",
       "      <td>黄埔区</td>\n",
       "      <td>113.450761,23.103239</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>020</td>\n",
       "      <td>440106</td>\n",
       "      <td>天河区</td>\n",
       "      <td>113.335367,23.13559</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>020</td>\n",
       "      <td>440104</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>113.280714,23.125624</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   citycode  adcode name                center     level districts\n",
       "0       020  440117  从化区  113.587386,23.545283  district        []\n",
       "1       020  440115  南沙区   113.53738,22.794531  district        []\n",
       "2       020  440114  花都区   113.211184,23.39205  district        []\n",
       "3       020  440113  番禺区  113.364619,22.938582  district        []\n",
       "4       020  440103  荔湾区  113.243038,23.124943  district        []\n",
       "5       020  440105  海珠区  113.262008,23.103131  district        []\n",
       "6       020  440111  白云区  113.262831,23.162281  district        []\n",
       "7       020  440118  增城区  113.829579,23.290497  district        []\n",
       "8       020  440112  黄埔区  113.450761,23.103239  district        []\n",
       "9       020  440106  天河区   113.335367,23.13559  district        []\n",
       "10      020  440104  越秀区  113.280714,23.125624  district        []"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def district(keywords,subdistrict=None,page=None,offset=None,extensions='base',filter=None,)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/config/district?parameters'\n",
    "    params={\n",
    "        'key':key_xu,\n",
    "        'keywords':keywords,\n",
    "        'subdistrict':subdistrict,\n",
    "        'page':page,\n",
    "        'offset':offset,\n",
    "        'extensions':extensions,\n",
    "        'filter':filter,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "行政区域 = district(keywords='广东',extensions='all',subdistrict=2)\n",
    "\n",
    "df_行政区域_1级 = pd.json_normalize(行政区域[\"districts\"][0]['districts'])\n",
    "\n",
    "df_行政区域_2级_广州市 = pd.json_normalize(行政区域[\"districts\"][0]['districts'][20]['districts'])\n",
    "display(df_行政区域_1级,df_行政区域_2级_广州市)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>center</th>\n",
       "      <th>level</th>\n",
       "      <th>districts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0758</td>\n",
       "      <td>441224</td>\n",
       "      <td>怀集县</td>\n",
       "      <td>112.182466,23.913072</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0758</td>\n",
       "      <td>441223</td>\n",
       "      <td>广宁县</td>\n",
       "      <td>112.440419,23.631486</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0758</td>\n",
       "      <td>441225</td>\n",
       "      <td>封开县</td>\n",
       "      <td>111.502973,23.434731</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0758</td>\n",
       "      <td>441284</td>\n",
       "      <td>四会市</td>\n",
       "      <td>112.695028,23.340324</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0758</td>\n",
       "      <td>441226</td>\n",
       "      <td>德庆县</td>\n",
       "      <td>111.78156,23.141711</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0758</td>\n",
       "      <td>441203</td>\n",
       "      <td>鼎湖区</td>\n",
       "      <td>112.565249,23.155822</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0758</td>\n",
       "      <td>441202</td>\n",
       "      <td>端州区</td>\n",
       "      <td>112.472329,23.052662</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0758</td>\n",
       "      <td>441204</td>\n",
       "      <td>高要区</td>\n",
       "      <td>112.460846,23.027694</td>\n",
       "      <td>district</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  citycode  adcode name                center     level districts\n",
       "0     0758  441224  怀集县  112.182466,23.913072  district        []\n",
       "1     0758  441223  广宁县  112.440419,23.631486  district        []\n",
       "2     0758  441225  封开县  111.502973,23.434731  district        []\n",
       "3     0758  441284  四会市  112.695028,23.340324  district        []\n",
       "4     0758  441226  德庆县   111.78156,23.141711  district        []\n",
       "5     0758  441203  鼎湖区  112.565249,23.155822  district        []\n",
       "6     0758  441202  端州区  112.472329,23.052662  district        []\n",
       "7     0758  441204  高要区  112.460846,23.027694  district        []"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_行政区域_2级"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搜索POI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 关键字搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '897',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'suggestion': {'keywords': [], 'cities': []},\n",
       " 'pois': [{'id': 'B00140BNNF',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '越秀公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '解放北路988号',\n",
       "   'location': '113.265609,23.140149',\n",
       "   'tel': '020-86661950',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140WGV9',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '花城广场',\n",
       "   'type': '风景名胜;公园广场;城市广场',\n",
       "   'typecode': '110105',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '珠江新城CBD中心区',\n",
       "   'location': '113.324596,23.120487',\n",
       "   'tel': '020-85601882',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140UEO1',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '广州动物园',\n",
       "   'type': '风景名胜;公园广场;动物园',\n",
       "   'typecode': '110102',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '先烈中路120号',\n",
       "   'location': '113.305371,23.140819',\n",
       "   'tel': '020-38377572',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140H4G8',\n",
       "   'parent': 'B0014014AD',\n",
       "   'childtype': '301',\n",
       "   'name': '云台花园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '广园中路801号白云山风景名胜区',\n",
       "   'location': '113.29395,23.157315',\n",
       "   'tel': '020-37229187',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '白云区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140SCPI',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '海珠广场',\n",
       "   'type': '风景名胜;公园广场;公园广场',\n",
       "   'typecode': '110100',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '泰康街',\n",
       "   'location': '113.266173,23.11445',\n",
       "   'tel': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00141JKQA',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '海珠湖',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '新滘中路168号',\n",
       "   'location': '113.322684,23.076688',\n",
       "   'tel': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '海珠区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140H465',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '天河公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '黄埔大道员村段',\n",
       "   'location': '113.366739,23.128003',\n",
       "   'tel': '020-85525020',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140CEZD',\n",
       "   'parent': 'B0FFFAJYVI',\n",
       "   'childtype': '301',\n",
       "   'name': '沙面公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '沙面南街3号',\n",
       "   'location': '113.244941,23.105827',\n",
       "   'tel': '020-81217557',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '荔湾区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140D02H',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '东山湖公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '东湖路123号',\n",
       "   'location': '113.292052,23.115193',\n",
       "   'tel': '020-87609086;020-87775672',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140UFB8',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '流花湖公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '流花路100号',\n",
       "   'location': '113.250145,23.136891',\n",
       "   'tel': '020-86664095;020-86662196',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140UEO5',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '华南植物园',\n",
       "   'type': '风景名胜;公园广场;植物园',\n",
       "   'typecode': '110103',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '天源路1190号',\n",
       "   'location': '113.367196,23.181797',\n",
       "   'tel': '020-85231993;020-85232037',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140U0TF',\n",
       "   'parent': 'B0014014AD',\n",
       "   'childtype': '301',\n",
       "   'name': '广州雕塑公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '下塘西路545号',\n",
       "   'location': '113.27061,23.148845',\n",
       "   'tel': '020-86351663',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140W3SH',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '太和文化广场(装修中)',\n",
       "   'type': '风景名胜;公园广场;城市广场',\n",
       "   'typecode': '110105',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '太和镇太和北路',\n",
       "   'location': '113.354802,23.295304',\n",
       "   'tel': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '白云区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140W60B',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '海心沙亚运公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '珠江新城临江大道',\n",
       "   'location': '113.325169,23.111717',\n",
       "   'tel': '020-38089668',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140UGBO',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '广州文化公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '西堤二马路37号',\n",
       "   'location': '113.251401,23.109669',\n",
       "   'tel': '020-81013963;020-81011981',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '荔湾区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B001423X57',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '白云湖',\n",
       "   'type': '风景名胜;公园广场;公园|风景名胜;风景名胜;省级景点',\n",
       "   'typecode': '110101|110203',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '白云湖大道',\n",
       "   'location': '113.237162,23.228402',\n",
       "   'tel': '020-26290219',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '白云区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFGC3HM3',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '广州海珠国家湿地公园',\n",
       "   'type': '风景名胜;公园广场;公园|风景名胜;风景名胜;国家级景点',\n",
       "   'typecode': '110101|110202',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '新滘中路168号',\n",
       "   'location': '113.336494,23.066696',\n",
       "   'tel': '020-89638182;020-89638185',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '海珠区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00140UFR2',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '晓港公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '前进路146号',\n",
       "   'location': '113.280706,23.096631',\n",
       "   'tel': '020-84474574',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '海珠区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00141IEZ6',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '越秀城市广场',\n",
       "   'type': '风景名胜;公园广场;城市广场',\n",
       "   'typecode': '110105',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '东风中路437-445号',\n",
       "   'location': '113.272085,23.131593',\n",
       "   'tel': '020-83548868',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '越秀区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B00141J5Y5',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '广州国际生物岛山地公园',\n",
       "   'type': '风景名胜;公园广场;公园',\n",
       "   'typecode': '110101',\n",
       "   'biz_type': 'tour',\n",
       "   'address': '官洲街道',\n",
       "   'location': '113.375645,23.065952',\n",
       "   'tel': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '海珠区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '2',\n",
       "   'poiweight': [],\n",
       "   'photos': []}]}"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def place_text(keywords,types,city=None,citylimit=None,children=None,page=None,extensions='base',sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params={\n",
    "        'key':key_xu,\n",
    "        'keywords':keywords,\n",
    "        'types':types,\n",
    "        'city':city,\n",
    "        'citylimit':citylimit,\n",
    "        'children':children,\n",
    "        'page':page,\n",
    "        'extensions':extensions,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "place_text('景点','110100',city=\"广州市\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 周边搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def place_around(keywords,types,city=None,citylimit=None,children=None,page=None,extensions='base',sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params={\n",
    "        'key':key_xu,\n",
    "        'keywords':keywords,\n",
    "        'types':types,\n",
    "        'city':city,\n",
    "        'citylimit':citylimit,\n",
    "        'children':children,\n",
    "        'page':page,\n",
    "        'extensions':extensions,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
